package com.xiaocg.proto;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Test {
    public static void main(String[] args)throws Exception {
        PrototypeObject prototypeObject = new PrototypeObject();
        prototypeObject.setName("xxxx");
        prototypeObject.setStu(new Stu());

        //通过对象流把对象序列化保存到文件中，在通过反序列化构建一个实例，则会新建一个不同的实例
        ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("e:\\a.txt"));
        o.writeObject(prototypeObject);
        o.close();

        ObjectInputStream i = new ObjectInputStream(new FileInputStream("e:\\a.txt"));
        PrototypeObject o1 = (PrototypeObject) i.readObject();

        System.out.println(prototypeObject.getStu() == o1.getStu());


    }
}
